describe-property is a property descriptor library that runs in both node.js and the browser. You use it to quickly generate property descriptors to use with Object.create
, Object.defineProperty
, and/or Object.defineProperties
.
Example
var d = require('describe-property');
function Person(firstName, surname) {
this.firstName = firstName;
this.surname = surname;
}
Object.defineProperties(Person.prototype, {
sayHi: d(function () {
console.log('Hello, my name is', this.fullName);
}),
fullName: d.gs(function () {
return this.firstName + ' ' + this.surname;
}),
firstName: d.gs(function () {
return this._firstName;
}, function (value) {
this._firstName = value.trim();
})
});
By default property descriptors use ES5 attributes.
{
configurable: true,
enumerable: false,
writable: true
}
But any of these can be overridden using an object literal.
d({
enumerable: true,
value: function () {
}
});
Installation
Using npm:
$ npm install describe-property
Issues
Please file issues on the issue tracker on GitHub.
Tests
To run the tests in node:
$ npm install
$ npm test
Credits
This library was inspired by @medikoo's excellent d library. It is intended to be a lighter-weight alternative with fewer features, but also only a single dependency.
License
MIT